const app = getApp()
const request = require('../../utils/request.js')

Page({
    data:{
        friend_page_list : [],
        is_no_one_in_friend_list:false,
        myOpenId:""
    },

    onLoad:function () {
        let that = this
        // 数据埋点--> 显示赚步数页面
        // request.dataBuried(buryDataStep.earn_show, 'earn_show', app.globalData.openId);
        let new_friend_list = app.globalData.friend_list
        if (new_friend_list.length!= 0){
            for (let i in new_friend_list){
                // 处理名字
                if (new_friend_list[i].nick_name.length > 4){
                    let new_name = new_friend_list[i].nick_name.substring(0,4) + "..."
                    new_friend_list[i].nick_name = new_name

                }else {
                    let new_name = new_friend_list[i].nick_name
                    new_friend_list[i].nick_name = new_name
                }
                // 处理步数加成数据
                let addtionStep = parseInt(new_friend_list[i].step/10)
                new_friend_list[i].addtionStep = addtionStep
                if (new_friend_list[i].step>0){
                    new_friend_list[i].btn_enable_work = false
                }else {
                    new_friend_list[i].btn_enable_work = true
                }
            }
            this.setData({
                friend_page_list:new_friend_list
            })
        } else {
            this.setData({
                friend_page_list:app.globalData.friend_list,
                is_no_one_in_friend_list:true,
                myOpenId:app.globalData.initUserInfo.open_id
            })
        }

    },

    onShareAppMessage: function (res) {
        if (res.target.id){
            let url = "/pages/index/index"
            let title = app.globalData.userInfo.nickName + "@你，赶紧来领取今日步数，抽取现金红包啦!"
            return {
                title: title,
                imageUrl: "/images/publicize_2.jpg",
                path: url,
            }
        } else {
            // 拼接分享url
            let url = "/pages/index/index?from_open_id=" + this.data.myOpenId
            let title = app.globalData.userInfo.nickName + "@你，【运动步数能赚钱】你还不知道吗？"
            return {
                title: title,
                imageUrl: "/images/publicize_3.jpg",
                path: url,
            }
        }

    },

    disable_click:function (e) {

    }

})